package com.yunzhong.appointment.essentialinformation.controller;

import com.github.pagehelper.PageInfo;
import com.yunzhong.appointment.entity.Bigthing;
import com.yunzhong.appointment.entity.Noticeboard;
import com.yunzhong.appointment.essentialinformation.service.IChronicleOfEventsService;
import com.yunzhong.appointment.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 王仁海
 * @author ThinkPad
 * @desc 大事记(富文本)
 */

/**
 * 何文博
 * 前台 大事记
 */
@Controller
@RequestMapping("baseinfo")
public class ChronicleOfEventsController {

    @Autowired
    private IChronicleOfEventsService chronicleOfEventsService;

    /**
     * 查询大事记信息
     *
     * @param request
     * @param mm
     * @return
     */


    @RequestMapping("listBigthing")
    public String listBigthing(HttpServletRequest request, ModelMap mm) {
        //接收前台数据
        PageData pd = new PageData(request);
        //判断是否为null
        if (pd.getString("professionalName") != null) {
            String professionalName = pd.getString("professionalName");
            pd.put("professionalName", professionalName.replace(" ", ""));
        }
        //查询数据
        List<Bigthing> varList = chronicleOfEventsService.queryNotes(pd);
        //得到分页数据
        PageInfo page = new PageInfo(varList);
        mm.put("page", page);
        mm.put("pd", pd);
        return "system/essentialinformation/chronicleofevents/listchronicleofevents";
    }


    /**
     * @return
     * @desc 转到添加页面
     */
    @RequestMapping("addBigthing")
    public String addpage() {
        return "system/essentialinformation/chronicleofevents/addchronicleofevents";
    }

    /**
     * 添加保存
     *
     * @return
     */
    @RequestMapping("saveBigthing")
    public String addsave(Bigthing dsj) {
        chronicleOfEventsService.save(dsj);
        return "redirect:listBigthing";
    }

    /**
     * @param mp
     * @param id
     * @return
     * @desc 转到修改页面
     */
    @RequestMapping("editBigthing")
    public String editpage(ModelMap mp, String id,String pageNum) {
        Bigthing byId = chronicleOfEventsService.queryById(id);
        mp.put("byId", byId);
        mp.put("pageNum", pageNum);
        return "system/essentialinformation/chronicleofevents/editchronicleofevents";
    }

    /**
     * 修改保存
     *
     * @param dsj
     * @return
     */
    @RequestMapping("editsaveBigthing")
    public String editsave(Bigthing dsj) {
        chronicleOfEventsService.edit(dsj);
        return "redirect:listBigthing";
    }

    /**
     * @param ids 主键集合
     * @param ra
     * @return
     * @desc 删除
     */
    @RequestMapping("removeBigthing")
    public String delete(String[] ids, RedirectAttributes ra) {
        chronicleOfEventsService.delete(ids);
        return "redirect:listBigthing";
    }
    /**
     * 查询
     */
    @RequestMapping("query")
    public String query(ModelMap mm,HttpServletRequest request) {
        PageData pd = new PageData(request);
       List<Bigthing> list =chronicleOfEventsService.queryNotes(pd);


        PageInfo page =new PageInfo(list);
        mm.put("page",page);
        return "bigthing/listBigthing";
    }
    /**
     * 查一条
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("pageFrontBigthing")
    public  String pageFrontBigthing(String id,ModelMap model){
        Bigthing bigthing=chronicleOfEventsService.queryById(id);
        model.addAttribute("bigthing",bigthing);


        return "bigthing/pageBigthing";
    }

}
